<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_model extends CI_Model {

	public function check($username) {
		$user = $this->db->get_where('admin', array('username'=>$username))
				->row_array();
		return $user;
	}

	public function add_user($data) {
		$this->db->insert('admin', $data);
		$uid = $this->db->insert_id();
		if ($uid) {
			$group_access = array(
			'uid' => $uid,
			'group_id' => $data['gid']
			);
			$this->db->insert('auth_group_access', $group_access);
		}
		
		return $uid;
	}

	public function edit_user($uid, $data) {
		$status = $this->db->update('admin', $data, array('uid'=>$uid));
		return $status;
	}

	public function edit_group_access($uid, $data) {
		$this->db->update('auth_group_access', $data, array('uid'=>$uid));
	}

	public function get_admin($uid = 0) {
		$this->db->from('admin a');
		$this->db->join('auth_group g', 'a.gid=g.id');
		if ($uid) {
			$this->db->where('a.uid', $uid);
		}
		$userinfo = $this->db->get()->result_array();
		return $userinfo;
	}


}

/* End of file admin_model.php */
/* Location: ./application/models/admin_model.php */